home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / gfx / misc / gnuplot-3.7src.lha / gnuplot-3.7src / gnuplot-3.7.lha / gnuplot-3.7 / eval.c < prev    next >
C/C++ Source or Header  |  1998-11-03  |  4KB  |  141 lines

  1. #ifndef lint
  2. static char *RCSid = "$Id: eval.c,v 1.15 1998/03/22 22:31:30 drd Exp $";
  3. #endif
  4.  
  5. /* GNUPLOT - eval.c */
  6.  
  7. /*[
  8.  * Copyright 1986 - 1993, 1998   Thomas Williams, Colin Kelley
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted,
  12.  * provided that the above copyright notice appear in all copies and
  13.  * that both that copyright notice and this permission notice appear
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the complete modified source code.  Modifications are to
  18.  * be distributed as patches to the released version.  Permission to
  19.  * distribute binaries produced by compiling modified sources is granted,
  20.  * provided you
  21.  *   1. distribute the corresponding source modifications from the
  22.  *    released version in the form of a patch file along with the binaries,
  23.  *   2. add special version identification to distinguish your version
  24.  *    in addition to the base release version number,
  25.  *   3. provide your name and address as the primary contact for the
  26.  *    support of your modified version, and
  27.  *   4. retain our contact information in regard to use of the base
  28.  *    software.
  29.  * Permission to distribute the released version of the source code along
  30.  * with corresponding source modifications in the form of a patch file is
  31.  * granted with same provisions 2 through 4 for binary distributions.
  32.  *
  33.  * This software is provided "as is" without express or implied warranty
  34.  * to the extent permitted by applicable law.
  35. ]*/
  36.  
  37.  
  38. #include "plot.h"
  39.  
  40.  
  41. struct udvt_entry *
  42.  add_udv(t_num)            /* find or add value and return pointer */
  43. int t_num;
  44. {
  45.     register struct udvt_entry **udv_ptr = &first_udv;
  46.  
  47.     /* check if it's already in the table... */
  48.  
  49.     while (*udv_ptr) {
  50.     if (equals(t_num, (*udv_ptr)->udv_name))
  51.         return (*udv_ptr);
  52.     udv_ptr = &((*udv_ptr)->next_udv);
  53.     }
  54.  
  55.     *udv_ptr = (struct udvt_entry *)
  56.     gp_alloc((unsigned long) sizeof(struct udvt_entry), "value");
  57.     (*udv_ptr)->next_udv = NULL;
  58.     copy_str((*udv_ptr)->udv_name, t_num, MAX_ID_LEN);
  59.     (*udv_ptr)->udv_value.type = INTGR;        /* not necessary, but safe! */
  60.     (*udv_ptr)->udv_undef = TRUE;
  61.     return (*udv_ptr);
  62. }
  63.  
  64.  
  65. struct udft_entry *
  66.  add_udf(t_num)            /* find or add function and return pointer */
  67. int t_num;            /* index to token[] */
  68. {
  69.     register struct udft_entry **udf_ptr = &first_udf;
  70.  
  71.     int i;
  72.     while (*udf_ptr) {
  73.     if (equals(t_num, (*udf_ptr)->udf_name))
  74.         return (*udf_ptr);
  75.     udf_ptr = &((*udf_ptr)->next_udf);
  76.     }
  77.  
  78.     /* get here => not found. udf_ptr points at first_udf or
  79.      * next_udf field of last udf
  80.      */
  81.  
  82.     if (standard(t_num))
  83.     int_warn("Warning : udf shadowed by built-in function of the same name", t_num);
  84.  
  85.     /* create and return a new udf slot */
  86.  
  87.     *udf_ptr = (struct udft_entry *)
  88.     gp_alloc((unsigned long) sizeof(struct udft_entry), "function");
  89.     (*udf_ptr)->next_udf = (struct udft_entry *) NULL;
  90.     (*udf_ptr)->definition = NULL;
  91.     (*udf_ptr)->at = NULL;
  92.     copy_str((*udf_ptr)->udf_name, t_num, MAX_ID_LEN);
  93.     for (i = 0; i < MAX_NUM_VAR; i++)
  94.     (void) Ginteger(&((*udf_ptr)->dummy_values[i]), 0);
  95.     return (*udf_ptr);
  96. }
  97.  
  98.  
  99. int standard(t_num)        /* return standard function index or 0 */
  100. int t_num;
  101. {
  102.     register int i;
  103.     for (i = (int) SF_START; ft[i].f_name != NULL; i++) {
  104.     if (equals(t_num, ft[i].f_name))
  105.         return (i);
  106.     }
  107.     return (0);
  108. }
  109.  
  110.  
  111.  
  112. void execute_at(at_ptr)
  113. struct at_type *at_ptr;
  114. {
  115.     register int i, index, count, offset;
  116.  
  117.     count = at_ptr->a_count;
  118.     for (i = 0; i < count;) {
  119.     index = (int) at_ptr->actions[i].index;
  120.     offset = (*ft[index].func) (&(at_ptr->actions[i].arg));
  121.     if (is_jump(index))
  122.         i += offset;
  123.     else
  124.         i++;
  125.     }
  126. }
  127.  
  128. /*
  129.  
  130.    'ft' is a table containing C functions within this program. 
  131.  
  132.    An 'action_table' contains pointers to these functions and arguments to be
  133.    passed to them. 
  134.  
  135.    at_ptr is a pointer to the action table which must be executed (evaluated)
  136.  
  137.    so the iterated line exectues the function indexed by the at_ptr and 
  138.    passes the address of the argument which is pointed to by the arg_ptr 
  139.  
  140.  */
  141.